 //
//  ZJIssueResourceViewController.m
//  ShangHaiHuDongApp
//
//  Created by ZJ on 2017/6/22.
//  Copyright © 2017年 刘应平. All rights reserved.
//

#import "ZJIssueResourceViewController.h"
#import "MyOTTypeView.h"
#import "ZJSIScopeView.h"
#import "ZJSILocationView.h"
#import "ZJSIPotoView.h"
#import "MyICRemarkView.h"
#import "ZLPhotoActionSheet.h"
#import "LPCostomChooseYearAndMonthAndDayDateView.h"
#import "ZJStartAndEndTimeView.h"
#import "ZJIsccueResoureUpLoadModel.h"
#import <AFNetworking.h>
#import <JCAlertView.h>
#import "LCustomAlertView.h"
#import "ZJUpAuditInfoModel.h"
#import "ZJRBTextFliedView.h"
#import "STPhotoBroswer.h"
#import "ZJIssueOrganizationSelectView.h"
@interface ZJIssueResourceViewController ()<ZJSILocationViewDelegate,ZJSIScopeViewDelegate,ZJSIPotoViewDelegate,LCustomAlertDelegate,UITextFieldDelegate,ZJIssueOrganizationSelectViewDelegate>
{
    NSInteger _index;/**< 标记图片数组的长度 */
    NSString *_scopeString;/**< 公开范围 */
    NSString *_resourceType;/**< 资源类型 */
    NSString *_issueTypeString;/**< 资源分类 */
    NSString *_astrictType;/**< 面向范围 */
    
    NSString *_latitude;/**< 纬度 */
    NSString *_longitude;/**< 经度 */
    ZJUpAuditInfoModel *_auditModel;/**< 需要提交审核的model */
    ZJIsccueResoureUpLoadModel * _upNetModel;/**< 上传信息model */
    BOOL _isStreet;/**< 是街道书记 */
    
    LCustomAlertView *_SHView;/**< 审核弹窗的View */
    LCustomAlertView *_deleImagesView;/**< 删除图片弹窗的View */
    NSInteger _deleImageIndex;/**< 删除图片的下标 */
    
    NSString *_organizationType;/**< 党组织类型 0:街镇党组织(默认)  1：大口党组织 */
    ZJIssueOrganModel *_organModel;/**< 大口党组织--选中的党组织信息 */
}
/** scrollview */
@property (nonatomic, strong) UIScrollView *scrollView;
/** 名字 */
@property (nonatomic, strong) ZJRBTextFliedView *name;
/** 资源分类 */
@property (nonatomic, strong) ZJSIScopeView *issueType;
/** 资源类型 */
@property (nonatomic, strong) ZJSIScopeView *type;
/** 提供方 */
@property (nonatomic, strong) ZJRBTextFliedView *offer;
/** 联系方式 */
@property (nonatomic, strong) ZJRBTextFliedView *phone;
/** 开放时间 */
@property (nonatomic, strong) ZJStartAndEndTimeView *startAndEndTimeView;
/** 一次性预约人数 */
@property (nonatomic, strong) ZJRBTextFliedView *number;
/** 场馆地址 */
@property (nonatomic, strong) ZJSILocationView *address;
/** 照片 */
@property (nonatomic, strong) ZJSIPotoView *potoView;
/** 备注 */
@property (nonatomic, strong) MyICRemarkView *remarkView;
/** 公开范围 */
@property (nonatomic, strong) ZJSIScopeView *scopeView;
/** 面向范围 */
@property (nonatomic, strong) ZJSIScopeView *astrict;
/** 发布 */
@property (nonatomic, strong) UIButton *button;
/** 时间选择器 */
@property (nonatomic, strong) LPCostomChooseYearAndMonthAndDayDateView *timeSeleView;
/** 图片数组 */
@property (nonatomic, strong) NSMutableArray *imageArray;
/** 弹窗视图 */
@property (nonatomic, strong) JCAlertView *alerView;
/** 弹窗视图 */
@property (nonatomic, strong) JCAlertView *deleAlerView;
/** 发布页面--大口党组织--组织选择的弹窗视图 */
@property (nonatomic, strong) ZJIssueOrganizationSelectView *organizationSelectView;
@end

@implementation ZJIssueResourceViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.titlelabel.text = @"发布资源";
    _scopeString = @"1";
    _resourceType = @"1";
    _astrictType = @"1";
    _issueTypeString = @"1";
    _organizationType = @"0";
    [self setupUI];
    [self judgeOrganizationType];
}

- (void)setupUI{
    [self.view addSubview:self.scrollView];
    [self.scrollView addSubview:self.name];
    [self.scrollView addSubview:self.issueType];
    [self.scrollView addSubview:self.type];
    [self.scrollView addSubview:self.offer];
    [self.scrollView addSubview:self.phone];
    [self.scrollView addSubview:self.startAndEndTimeView];
    [self.scrollView addSubview:self.number];
    [self.scrollView addSubview:self.address];
    [self.scrollView addSubview:self.potoView];
    [self.scrollView addSubview:self.remarkView];
    [self.scrollView addSubview:self.scopeView];
    [self.scrollView addSubview:self.astrict];
    [self.scrollView addSubview:self.button];
    
    self.name.sd_layout
    .topSpaceToView(self.scrollView, 0)
    .leftSpaceToView(self.scrollView, 0)
    .rightSpaceToView(self.scrollView, 0)
    .heightIs(self.name.height);
    
    self.issueType.sd_layout
    .topSpaceToView(self.name, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.issueType.height);
    
    self.type.sd_layout
    .topSpaceToView(self.issueType, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.type.height);
    
    self.offer.sd_layout
    .topSpaceToView(self.type, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.offer.height);
    
    self.phone.sd_layout
    .topSpaceToView(self.offer, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.phone.height);
    
    self.startAndEndTimeView.sd_layout
    .topSpaceToView(self.phone, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.startAndEndTimeView.height);
    
    self.number.sd_layout
    .topSpaceToView(self.startAndEndTimeView, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.number.height);
    
    self.address.sd_layout
    .topSpaceToView(self.number, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.address.height);
    
    self.potoView.sd_layout
    .topSpaceToView(self.address, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.potoView.height);
    
    self.remarkView.sd_layout
    .topSpaceToView(self.potoView, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.remarkView.height);
    
    self.scopeView.sd_layout
    .topSpaceToView(self.remarkView, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.scopeView.height);
    
    self.astrict.sd_layout
    .topSpaceToView(self.scopeView, 0)
    .leftEqualToView(self.name)
    .rightEqualToView(self.name)
    .heightIs(self.astrict.height);
    
    self.button.sd_layout
    .topSpaceToView(self.astrict, 22 * [UIScreen zj_screenWScale])
    .leftSpaceToView(self.scrollView, 38 * [UIScreen zj_screenWScale])
    .rightSpaceToView(self.scrollView, 38 * [UIScreen zj_screenHScale])
    .heightIs(44 * [UIScreen zj_screenHScale]);
    
    [self.scrollView setupAutoContentSizeWithBottomView:self.button bottomMargin:30 * [UIScreen zj_screenHScale]];
}


#pragma mark - 判断是 街镇党组织 还是 大口党组织
- (void)judgeOrganizationType{
//    [YJProgressHUD showMessage:@"加载中..." duration:10 view:self.view];
    __weak typeof(self) weakSelf = self;
    NSDictionary *dict = @{@"FROM_UNITID":[NSString string:ZJUSERINFORMODEL.CURRENT_ROLE_MODEL.DEPT_ID isNilStringReturnDeftString:@""]};
    [NetWorkingManager postWithUrlString:[NetWorkingURL getTree] Parameter:dict Success:^(id object) {
//        [YJProgressHUD hide];
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            _organizationType = [object objectForKey:@"ISDOWN"];
            if ([[object objectForKey:@"ISDOWN"] isEqualToString:@"0"]) {//街镇党组织
                //三个： 全区  街镇党组织  本支部
                weakSelf.organizationSelectView.dataArray = [[NSArray yy_modelArrayWithClass:[ZJIssueOrganModel class] json:[object objectForKey:@"DEPT_TREE"]] mutableCopy];
                [weakSelf getUserTypeUpdateScopeView];
            }else{//大口党组织
                
                [weakSelf.scopeView minUpdataUI_dataArray:@[@"本支部",@"组织选择",@"全区"] selectString:nil];
                weakSelf.organizationSelectView.dataArray = [[NSArray yy_modelArrayWithClass:[ZJIssueOrganModel class] json:[object objectForKey:@"DEPT_TREE"]] mutableCopy];
            }
        }
    } Fail:^(id object) {
//        [YJProgressHUD hide];
    }];
}

#pragma mark - 判断当前用户身份--来改变功盖范围的UI界面
- (void)getUserTypeUpdateScopeView{
    __weak typeof(self) weakSelf = self;
    if (self.isSecretary) {//是书记    0支部    1 街道
        [self netWorking_secretary:^(NSString *secretaryType) {
            if ([secretaryType isEqualToString:@"1"]) {//街道的书记、
                [weakSelf.scopeView updataUI_dataArray:@[@"街镇党组织",@"全区"] selectString:nil];
                _scopeString = @"2";
                _isStreet = YES;
            }
        }];
    }
}

- (void)netWorking_secretary:(void(^)(NSString * secretaryType))secretary{
    [NetWorkingManager postWithUrlString:[NetWorkingURL informactsSelectValue] Parameter:@{@"ACCOUNTID":ZJUSERINFORMODEL.ORG_ACCOUNT.ID} Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {
            secretary([object objectForKey:@"DEPTTYPE_DSCODE_VALUE"]);
        }
    } Fail:^(id object) {
        
    }];
    
}

#pragma mark - LCustomAlertDelegate(弹窗提示) 协议方法
- (void)lCustomAlertWithView:(LCustomAlertView *)view index:(NSInteger)index{
    if (view == _SHView) {
        [self.alerView dismissWithCompletion:nil];
        if (index == 1) {
            [YJProgressHUD showMessage:@"审核中..." duration:10 view:self.view];
            [self netWorking_audit];
        }else{
            [self.navigationController popViewControllerAnimated:YES];
        }
        
    }
}
#pragma mark - ZJSILocationViewDelegate(定位) 协议方法
- (void)ZJSILocationViewDelegate_latitude:(NSString *)latitude longitude:(NSString *)longitude{
    _latitude = latitude;
    _longitude = longitude;
}

#pragma mark - ZJIssueOrganizationSelectViewDelegate(发布页面--大口党组织--组织选择的弹窗视图) 协议方法
- (void)ZJIssueOrganizationSelectViewDelegate_cellSelected_Model:(ZJIssueOrganModel *)model{
    _organModel = model;
    [self.scopeView minUpdataUI_dataArray:@[@"本支部",model.DEPT_NAME,@"全区"] selectString:@"1"];
}

#pragma mark - ZJSIScopeViewDelegate(资源类型、资源分类、公开范围、面向范围的选择) 协议方法
- (void)ZJSIScopeViewClick_scopeView:(ZJSIScopeView *)scopeView index:(NSInteger)index{
    NSString *string = [NSString stringWithFormat:@"%ld",index + 1];
    if (scopeView == self.scopeView) {//公开范围
        _scopeString = string;
        if (_isStreet) {//街道书记
            string = [NSString stringWithFormat:@"%ld",index + 2];
            _scopeString = string;
        }
        if (index == 1 && [_organizationType isEqualToString:@"1"]) {//大口党组织--组织选择
            [self addOrganizationselectview];
        }

    }else if( scopeView == self.type){//资源类型
        _resourceType = string;
    }else if( scopeView == self.issueType){//资源分类
        if ([string isEqualToString:@"2"]) {
            _issueTypeString = @"0";
        }else{
            _issueTypeString = string;
        }
    }else if( scopeView == self.astrict){//面向范围
        _astrictType = string;
    }

}

///添加选择视图 （大口党组织--组织选择）
- (void)addOrganizationselectview{
    self.organizationSelectView.alpha = 0;
    [self.view addSubview:self.organizationSelectView];
    [UIView animateWithDuration:0.5 animations:^{
        self.organizationSelectView.alpha = 1;
    }];
}

#pragma mark - UITextFieldDelegate 协议方法
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    NSString * toBeString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    if (toBeString.length >= 11 && range.length!=1){
        textField.text = [toBeString substringToIndex:11];
        return NO;
        
    }
    return YES;
}
#pragma mark - ZJSIPotoViewDelegate(图片模块) 协议方法
- (void)ZJSIPotoViewDelegate_addPotoClick{
    [self.view endEditing:YES];
    _index = self.imageArray.count;
    //图片多选模块
    ZLPhotoActionSheet *actionSheet = [[ZLPhotoActionSheet alloc] init];
    //设置最大选择数量
    actionSheet.maxSelectCount = 9;
    //设置预览图最大数目
    actionSheet.maxPreviewCount = 20;
    __weak typeof(self) weakSelf = self;
    [actionSheet showWithSender:self animate:YES lastSelectPhotoModels:nil completion:^(NSArray<UIImage *> * _Nonnull selectPhotos, NSArray<ZLSelectPhotoModel *> * _Nonnull selectPhotoModels) {
        
        [selectPhotos enumerateObjectsUsingBlock:^(UIImage * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            NSData * data = [ToolClass compressionImageWithImage:obj compressionMaxLimit:COMPRESSIONMAXLIMIT];
            NetWorkUploadFileModel *model = [NetWorkUploadFileModel new];
            model.FILE_NAME = [NSDateFormatter stringTimeWithDate:[NSDate date]];
            model.FILE_INDEX = [NSString stringWithFormat:@"%ld",idx];
            model.FILE_PATH = data;
            model.NAME = @"IMG_URL";
            [weakSelf.imageArray addObject:model];
        }];
        _index = self.imageArray.count;
        [weakSelf.potoView updateUI_PotoArray:weakSelf.imageArray];
        weakSelf.potoView.sd_layout
        .topSpaceToView(self.address, 0)
        .leftSpaceToView(self.scrollView, 0)
        .rightSpaceToView(self.scrollView, 0)
        .heightIs(self.potoView.height);
        
    }];

}
- (void)ZJSIPotoViewDelegate_deletePotoClick_index:(NSInteger)index{
    _deleImageIndex = index;
    UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"是否确定删除图片" message:nil preferredStyle:UIAlertControllerStyleAlert];
    [alertController addAction:[UIAlertAction actionWithTitle:@"确认" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        [self.imageArray removeObjectAtIndex:_deleImageIndex];
        _index = self.imageArray.count;
        [self.potoView updateUI_PotoArray:self.imageArray];
        self.potoView.sd_layout
        .topSpaceToView(self.address, 0)
        .leftEqualToView(self.name)
        .rightEqualToView(self.name)
        .heightIs(self.potoView.height);
    }]];
    [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
        
    }]];
    [self presentViewController:alertController animated:YES completion:nil];
    


}
- (void)ZJSIPotoViewDelegate_potoImageClick_index:(NSInteger)index{
    __block NSMutableArray *imageDataArray = [NSMutableArray array];
    [self.imageArray enumerateObjectsUsingBlock:^(NetWorkUploadFileModel *  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        NSDictionary *dict = @{@"image":[UIImage imageWithData:obj.FILE_PATH]};
        [imageDataArray addObject:dict];
    }];
    STPhotoBroswer *view = [[STPhotoBroswer alloc]initWithFrame:CGRectMake(0, 0,self.view.width , self.view.height) ImageArray:imageDataArray currentIndex:index];
    [view show];
}


#pragma mark - 发布资源
- (void)action_affirmButton{
    if (self.name.textField.text.length == 0) {
         [YJProgressHUD showSuccess:@"请输入资源名称" inview:self.view];
        [self.name.textField becomeFirstResponder];
        return;
    }
    if (self.offer.textField.text.length == 0) {
        [YJProgressHUD showSuccess:@"请输入提供方" inview:self.view];
        [self.offer.textField becomeFirstResponder];
        return;
    }
    if (self.phone.textField.text.length < 5) {
        [YJProgressHUD showSuccess:@"请输入正确的联系方式" inview:self.view];
        [self.phone.textField becomeFirstResponder];
        return;
    }
    if (self.number.textField.text.length == 0 || [self.number.textField.text integerValue]  < 1) {
        [YJProgressHUD showSuccess:@"请输入预约人数" inview:self.view];
        [self.number.textField becomeFirstResponder];
        return;
    }
    if (self.remarkView.textView.text.length == 0) {
        [YJProgressHUD showSuccess:@"请输入简介" inview:self.view];
        [self.remarkView.textView becomeFirstResponder];
        return;
    }
    
    [self netWorkingUpData];
    
}

//发布资源
- (void)netWorkingUpData{
    ZJIsccueResoureUpLoadModel * model = [ZJIsccueResoureUpLoadModel new];
    model.SYS_ACCOUNTID = ZJUSERINFORMODEL.ORG_ACCOUNT.ID ? ZJUSERINFORMODEL.ORG_ACCOUNT.ID :@"";
    model.SYS_PARTYMEMBERID = ZJUSERINFORMODEL.ORG_ACCOUNT.PARTY_MEMBER_ID ? ZJUSERINFORMODEL.ORG_ACCOUNT.PARTY_MEMBER_ID : @"";
    model.UPLOAD_FILES = self.imageArray;
    model.NAME = self.name.textField.text;
    model.RESOURCETYPE = _resourceType;
    model.RESOURCE_PRINCIPAL = self.offer.textField.text;
    model.STARTTIME = self.startAndEndTimeView.startTime.time.text ;
    model.ENDTIME = self.startAndEndTimeView.endTime.time.text;
    model.PEOPLE_NUM = self.number.textField.text;
    model.DESCRIPTION = self.remarkView.textView.text;
    model.FROM_USERID = [ZJUserInfoModel sharedUserInfo].CURRENT_USER_MODEL.ID;
    model.ADDRESS = self.address.loactionLabel.text;
    model.LAT = _latitude;
    model.LNG = _longitude;
    model.WORTH = @"";
    model.SCORE = @"";
    model.EXPECT_STATE = _scopeString;
    model.TORANG = _astrictType;
    if (self.isSecretary) {//是书记工作台进入
        model.FROM = @"2";
        model.FROM_UNITID = [ZJUserInfoModel sharedUserInfo].CURRENT_ROLE_MODEL.DEPT_ID;
    }else{
        model.FROM = @"1";
        model.FROM_UNITID = [ZJUserInfoModel sharedUserInfo].CURRENT_DEPT_MODEL.ID;
    }
    model.RESOURCECLASS = _issueTypeString;
    model.SENDTO_DAPTID = @"";
    if ([_organizationType isEqualToString:@"1"]) {//大口党组织
        if ([_scopeString isEqualToString:@"1"]) {//本支部
            model.SENDTO_DAPTID = [NSString string:ZJUSERINFORMODEL.CURRENT_ROLE_MODEL.DEPT_ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"2"]) {//组织选择
            model.SENDTO_DAPTID = [NSString string:_organModel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"3"]) {//全区
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[0];
            model.SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }
    }else{//街镇党组织
        //self.organizationSelectView.dataArray三个： 全区  街镇党组织  本支部
        if ([_scopeString isEqualToString:@"1"]) {//本支部
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[2];
            model.SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"2"]) {//街道党组织
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[1];
            model.SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"3"]) {//全区
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[0];
            model.SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }
    }


    _upNetModel = model;
    [self senderNetWorkingModel:model];
}

//网络请求
- (void)senderNetWorkingModel:(NetWorkUpLoadModel *)parameter{
    [YJProgressHUD showMessage:@"发布中..." duration:10 view:self.view];
    __weak typeof(self) weakSelf = self;
    ZJIsccueResoureUpLoadModel *parameter1 = (ZJIsccueResoureUpLoadModel *)parameter;
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/json",@"text/html",@"text/javascript",@"text/plain", nil];
    
    //1、把文件对象数组转化成数组
    NSArray *fileArray = [parameter1.UPLOAD_FILES yy_modelToJSONObject];
    //2、除去data，得到数组
    __block NSMutableArray *nofileDataArray = [NSMutableArray array];//保存新数组
    
    NSDictionary *netWorkUpLoadModel = [parameter1 yy_modelToJSONObject];
    
    [fileArray enumerateObjectsUsingBlock:^(NSMutableDictionary * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        [obj removeObjectForKey:@"fileUrl"];
        [nofileDataArray addObject:obj];
    }];
  
    
    NSString * dateString = [NSString stringWithFormat:@"FILES_%@_KEYS",[NSString getCurrentDate]];
    
    [manager POST:UPLOADURL parameters:nil constructingBodyWithBlock:^(id<AFMultipartFormData>  _Nonnull formData) {
        
        [netWorkUpLoadModel.allKeys enumerateObjectsUsingBlock:^(NSString *  _Nonnull key, NSUInteger idx, BOOL * _Nonnull stop) {
            //不为fileArray 且有值时
            if (![key isEqualToString:@"UPLOAD_FILES"] && [netWorkUpLoadModel objectForKey:key] && ![key isEqualToString:@"frequency"]) {
                [formData appendPartWithFormData:[netWorkUpLoadModel[key] dataUsingEncoding:NSUTF8StringEncoding] name:key];
            }
        }];
        
        [parameter1.UPLOAD_FILES enumerateObjectsUsingBlock:^(NetWorkUploadFileModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            if (obj.FILE_PATH) {
                NSData  *fileData= obj.FILE_PATH;//二进制数据
                NSString *mimeType= @"image/jpeg";//文件类型
            
                //拼接最新的文件名
                NSString *fileName = [NSString stringWithFormat:@"%ld%@",(unsigned long)idx,@".jpg"];
                [formData appendPartWithFileData:fileData name: obj.NAME fileName:fileName mimeType:mimeType];
            }
        }];
        
        [formData appendPartWithFormData:[nofileDataArray yy_modelToJSONData] name:dateString];
        [formData appendPartWithFormData:[[NetWorkingURL addResour] dataUsingEncoding:NSUTF8StringEncoding] name:@"ACTION_XML"];
        
    } progress:^(NSProgress * _Nonnull uploadProgress) {
        //进度
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //成功
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:responseObject];
        if ([model.STATE isEqualToString:@"20000"]) {
            
            [MobClick event:[UMMStatisticsString publishService]];
            ZJUpAuditInfoModel *auditModel = [ZJUpAuditInfoModel yy_modelWithJSON:responseObject];
            if ([auditModel.ISCHECK isEqualToString:@"1"]) {//需要提交审核
                _auditModel = auditModel;
                UIAlertController * alertController = [UIAlertController alertControllerWithTitle:@"该信息需经上级党组织审核后发布,您确定要继续吗" message:nil preferredStyle:UIAlertControllerStyleAlert];
                [alertController addAction:[UIAlertAction actionWithTitle:@"继续" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
                    [weakSelf netWorking_audit];
                }]];
                [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                }]];
                [weakSelf presentViewController:alertController animated:YES completion:nil];
            }else{
                if (weakSelf.block) {
                    weakSelf.block();
                }
             [YJProgressHUD showSuccess:@"发布成功" inview:weakSelf.view];
                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                    [weakSelf.navigationController popViewControllerAnimated:YES];
                });
            }
        }else{
            [YJProgressHUD showSuccess:@"发布失败" inview:weakSelf.view];
        
        }
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        //失败
        [YJProgressHUD showSuccess:@"发布失败" inview:weakSelf.view];
      
    }];
}

//提交审核
- (void)netWorking_audit{
    [YJProgressHUD showMessage:@"审核中..." duration:10 view:self.view];
    NSString *SENDTO_DAPTID = @"";
    if ([_organizationType isEqualToString:@"1"]) {//大口党组织
        if ([_scopeString isEqualToString:@"1"]) {//本支部
            SENDTO_DAPTID = [NSString string:ZJUSERINFORMODEL.CURRENT_ROLE_MODEL.DEPT_ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"2"]) {//组织选择
            SENDTO_DAPTID = [NSString string:_organModel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"3"]) {//全区
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[0];
            SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }
    }else{//街镇党组织
        //self.organizationSelectView.dataArray三个： 全区  街镇党组织  本支部
        if ([_scopeString isEqualToString:@"1"]) {//本支部
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[2];
            SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"2"]) {//街道党组织
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[1];
            SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }else if ([_scopeString isEqualToString:@"3"]) {//全区
            ZJIssueOrganModel *orgmodel = self.organizationSelectView.dataArray[0];
            SENDTO_DAPTID = [NSString string:orgmodel.ID isNilStringReturnDeftString:@""];
        }
    }

    NSDictionary *dict = @{@"REL_ID":_auditModel.REL_ID,
                           @"EXPECT_STATE":_upNetModel.EXPECT_STATE,
                           @"FROM_USERID":[ZJUserInfoModel sharedUserInfo].CURRENT_USER_MODEL.ID,
                           @"FROM_UNITID":[ZJUserInfoModel sharedUserInfo].CURRENT_ROLE_MODEL.DEPT_ID,
                           @"CONTENT":_upNetModel.DESCRIPTION,
                           @"UPDATE":@"0",
                           @"ISMOBILE":@"1",
                           @"NAME":_upNetModel.NAME,
                           @"SENDTO_DAPTID":SENDTO_DAPTID};
    __weak typeof(self) weakSelf = self;
    [NetWorkingManager postWithUrlString:[NetWorkingURL postResourcePublishRq] Parameter:dict Success:^(id object) {
        NetWorkModel *model = [NetWorkModel yy_modelWithJSON:object];
        if ([model.STATE isEqualToString:@"20000"]) {//审核成功
            [YJProgressHUD showSuccess:@"审核成功" inview:weakSelf.view];
            if (weakSelf.block) {
                weakSelf.block();
            }
           
        }else{
            [YJProgressHUD showSuccess:@"审核失败" inview:weakSelf.view];
        }
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });

    } Fail:^(id object) {
        [YJProgressHUD showSuccess:@"审核失败" inview:weakSelf.view];
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
            [weakSelf.navigationController popViewControllerAnimated:YES];
        });
     
    }];
}

#pragma mark - Getter
- (UIScrollView *)scrollView{
    if (_scrollView == nil){
        _scrollView = [[UIScrollView alloc]initWithFrame:CGRectMake(0, LP_TopHeight, self.view.width, self.view.height - LP_TopHeight)];
    }
    return _scrollView;
}

- (ZJRBTextFliedView *)name{
    if (_name == nil){
        _name = [[ZJRBTextFliedView alloc] initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenWScale], self.view.width, 90 * [UIScreen zj_screenHScale]) title:@"名称 :"];
        _name.maxNumber = 50;
        [self setViewUpdate:_name];
    }
    return _name;
}

- (ZJSIScopeView *)issueType{
    if (_issueType == nil){
        _issueType = [[ZJSIScopeView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 195  * [UIScreen zj_screenHScale]) title:@"资源分类 :"];
        [_issueType minUpdataUI_dataArray:@[@"区域单位资源",@"本组织资源"] selectString:nil];
        _issueType.delegate = self;
    }
    return _issueType;
}

- (ZJSIScopeView *)type{
    if (_type == nil){
        _type = [[ZJSIScopeView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 195  * [UIScreen zj_screenHScale]) title:@"资源类型 :"];
        [_type updataUI_dataArray:@[@"场地设施",@"便民服务",@"实物物品"] selectString:nil];
        _type.delegate = self;
    }
    return _type;
}
- (ZJRBTextFliedView *)offer{
    if (_offer == nil){
        _offer = [[ZJRBTextFliedView alloc] initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenWScale], self.view.width, 90 * [UIScreen zj_screenHScale]) title:@"提供方 :"];
        _offer.maxNumber = 50;
        [self setViewUpdate:_offer];
    }
    return _offer;
}
- (ZJRBTextFliedView *)phone{
    if (_phone == nil){
        _phone = [[ZJRBTextFliedView alloc] initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenWScale], self.view.width, 90 * [UIScreen zj_screenHScale]) title:@"联系方式 :"];
        _phone.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _phone.textField.delegate = self;
        [self setViewUpdate:_phone];
    }
    return _phone;
}
- (ZJRBTextFliedView *)number{
    if (_number == nil){
        _number = [[ZJRBTextFliedView alloc] initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenWScale], self.view.width, 90 * [UIScreen zj_screenHScale]) title:@"一次性预约人数 :"];
        _number.textField.keyboardType = UIKeyboardTypeNumbersAndPunctuation;
        _number.isNumber = YES;
        _number.maxNumber = 10;
        [self setViewUpdate:_number];
    }
    return _number;
}
- (ZJSILocationView *)address{
    if (_address == nil){
        _address = [[ZJSILocationView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 90  * [UIScreen zj_screenHScale]) title:@"场馆地址 :"];
        _address.maxNumber = 10;
        _address.delegate = self;
    }
    return _address;
}
- (ZJSIPotoView *)potoView{
    if (_potoView == nil){
        _potoView = [[ZJSIPotoView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 195  * [UIScreen zj_screenHScale]) title:@"照片（ 非必填 ） :"];
        [_potoView updateUI_PotoArray:nil];
        _potoView.deletate = self;
    }
    return _potoView;
}
- (MyICRemarkView *)remarkView{
    if (_remarkView == nil){
        _remarkView = [[MyICRemarkView alloc]initWithFrame:CGRectMake(0, LP_TopHeight + 20 * [UIScreen zj_screenHScale], self.view.width, 195 * [UIScreen zj_screenHScale]) title:@"简介 :"];
        _remarkView.maxNumber = 200;
    }
    return _remarkView;
}
- (ZJStartAndEndTimeView *)startAndEndTimeView{
    if (_startAndEndTimeView == nil){
        _startAndEndTimeView = [[ZJStartAndEndTimeView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 90 *[UIScreen zj_screenHScale]) title:@"开放时间 :"];
        _startAndEndTimeView.startTime.time.text = @"09:00";
        _startAndEndTimeView.endTime.time.text = @"18:00";
    }
    return _startAndEndTimeView;
}

- (ZJSIScopeView *)scopeView{
    if (_scopeView == nil){
        _scopeView = [[ZJSIScopeView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 195  * [UIScreen zj_screenHScale]) title:@"公开范围 :"];
        [_scopeView updataUI_dataArray:@[@"本支部",@"街镇党组织",@"全区"] selectString:nil];
        _scopeView.delegate = self;
    }
    return _scopeView;
}
- (ZJSIScopeView *)astrict{
    if (_astrict == nil){
        _astrict = [[ZJSIScopeView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, 195  * [UIScreen zj_screenHScale]) title:@"面向范围 :"];
        [_astrict minUpdataUI_dataArray:@[@"组织",@"个人",@"组织及个人"] selectString:nil];
        _astrict.delegate = self;
    }
    return _astrict;
}

- (UIButton *)button{
    if (_button == nil){
        _button = [UIButton new];
        [_button setTitle:@"确认发布" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _button.layer.cornerRadius = 4 * [UIScreen zj_screenWScale];
        _button.titleLabel.font = [UIFont titleTextFont];
        _button.backgroundColor = [UIColor themeColor];
        [_button addTarget:self action:@selector(action_affirmButton) forControlEvents:UIControlEventTouchUpInside];
        
    }
    return _button;
}
- (NSMutableArray *)imageArray{
    if (_imageArray == nil){
        _imageArray = [NSMutableArray array];
        
    }
    return _imageArray;
}
- (JCAlertView *)alerView{
    if (_alerView == nil){
        _SHView = [[LCustomAlertView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], [UIScreen zj_screenHeight]) alertMessage:@"是否提交审核" titlesArray:@[@"取消",@"确认"]];
        _SHView.delegate = self;
        _alerView = [[JCAlertView alloc] initWithCustomView:_SHView dismissWhenTouchedBackground:YES];
    }
    return _alerView;
}

- (JCAlertView *)deleAlerView{
    if (_deleAlerView == nil){
        _deleImagesView = [[LCustomAlertView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen zj_screenWith], [UIScreen zj_screenHeight]) alertMessage:@"是否删除图片" titlesArray:@[@"取消",@"确认"]];
        _deleImagesView.delegate = self;
        _deleAlerView = [[JCAlertView alloc] initWithCustomView:_deleImagesView dismissWhenTouchedBackground:YES];
    }
    return _deleAlerView;
}

- (ZJIssueOrganizationSelectView *)organizationSelectView{
    if (_organizationSelectView == nil){
        _organizationSelectView = [[ZJIssueOrganizationSelectView alloc] initWithFrame:[UIScreen mainScreen].bounds];
        _organizationSelectView.delegate = self;
    }
    return _organizationSelectView;
}

- (void)setViewUpdate:(ZJRBTextFliedView *)viewUpdate{
    viewUpdate.titleLabel.frame = CGRectMake(12 * [UIScreen zj_screenWScale], viewUpdate.titleLabel.y, self.view.width - 24 * [UIScreen zj_screenWScale], viewUpdate.titleLabel.height);
    viewUpdate.textField.frame = CGRectMake(12 * [UIScreen zj_screenWScale], viewUpdate.textField.y, self.view.width - 24 * [UIScreen zj_screenWScale], viewUpdate.textField.height);
}
@end
